package com.hhw.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hhw.entity.Order;
import com.hhw.entity.OrderPage;
import com.hhw.entity.Page;
import com.hhw.service.OrderPageService;


/**
 * Servlet implementation class Toorderlist
 */
@WebServlet("/toorderlist")
public class Toorderlist extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Toorderlist() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String orderpageNum=request.getParameter("orderpageNum");
		int num=0;
		if(orderpageNum==null || orderpageNum.equals("")){
			num=1;
		}else{
			num=Integer.parseInt(orderpageNum);
		}
		//调用业务逻辑层对象，处理结果实现跳转
		OrderPageService ps=new OrderPageService();
		int count=ps.findOrderPage();
		List<Order> list=ps.findOrderByPage(num, 4);
		
		
		OrderPage<Order> p=new OrderPage<Order>(num,4);
		//p.setList(list);
		p.setOrderlist(list);
		p.setOrdertotalCount(count);
	//	p.setTotalCount(count);
		request.setAttribute("order", p);
		
		request.getRequestDispatcher("/WEB-INF/jsp/orderlist.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
